package com.xjj.service.health.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xjj.entity.Health;
import com.xjj.entity.Leave;
import com.xjj.entity.PageBean;
import com.xjj.entity.Student;
import com.xjj.service.health.mapper.HealthMapper;
import com.xjj.service.health.service.HealthService;
import com.xjj.service.health.vo.HealthSubmit;
import com.xjj.service.mapper.StudentMapper;
import com.xjj.vo.HealthVo;
import com.xjj.vo.LeaveVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @Auther: AYang
 * @Date: 2022/10/28 09:27
 * @Description:
 */
@Service
public class HealthServiceImpl extends ServiceImpl<HealthMapper, Health> implements HealthService {
    @Autowired
    private HealthMapper healthMapper;

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public PageBean<Health> getByPage(Health health, Integer pageNum, Integer pageSize) {
        PageBean<Health> pageBean = new PageBean<>();
        Page page = PageHelper.startPage(pageNum, pageSize);
        List<Health> healthList = healthMapper.getByCondition(health);
        log.debug("healthList:{}" + healthList);

        pageBean.setCurrPage(pageNum);
        pageBean.setData(healthList);
        pageBean.setCurrPageSize(healthList.size());
        pageBean.setPageSize(pageSize);
        pageBean.setTotalPages(page.getPages());
        pageBean.setTotalNums((int) page.getTotal());
        return pageBean;
    }

    @Override
    public void updateStatusById(Integer id, String status,String checkTime) {
        healthMapper.updateStatusById(id,status,checkTime);
    }

    @Override
    public List<Health> getByStudent(Integer studentId, String status) {
        Health health = new Health();
        health.setStudentId(studentId);
        health.setStatus(status);
        return healthMapper.getByCondition(health);
    }

    @Override
    public Integer addHealth(Health health) {
        health.setDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        health.setStatus("n");
        health.setSendTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        health.setImg("https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg");
        save(health);
        return health.getId();
    }

    @Override
    public void add(Health health) {
        health.setStudentId(studentMapper.selectById(health.getStudentId()).getId());
        health.setDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        health.setSendTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        health.setCheckTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        health.setStatus("n");
        save(health);
    }

    @Override
    public void addHealthImg(Integer id, List<String> imgList) {
        for (String img : imgList) {
            healthMapper.addHealthImg(id, img);
        }
    }
}
